from python_baway.common.xcommon import sep

f1 = lambda a, b: a + b
print(f1(2, 3))

f2 = lambda: print('In lambda')
print(f2())


# All python functions are first order objects (they can be passed as arguments), lambda is just a convenient way to make short ones. In general, you are better off using a normal function definition if it becomes anything beyond one line of simple code.
def f3():
    import random
    n = random.randint(1, 100)
    print('In f3, n=', n)


print(f3())

# print('V = ' + (lambda x, y, z: x * y * z)(10, 20, 30))  # TypeError: can only concatenate str (not "int") to str
print('V = ' + str((lambda x, y, z: x * y * z)(10, 20, 30)))
print('I say that: ' + (lambda: 'Hello, world!')())

# lambda also has default parameters
# 2.创建匿名函数，实现3个数的积，3个参数默认值分别为1、2、3
print(f'1 + 2 + 3 = {(lambda x = 1, y = 2, z = 3: x + y + z)()}')